#include "btform.h"
#include "ui_btform.h"
#include<QRect>
#include<QDebug>

btForm::btForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::btForm)
{
    ui->setupUi(this);
    //设置动画
    SetQPAnimation(1500,animationline1,QRect(5,20,2,12),ui->line1);
    SetQPAnimation(1600,animationline2,QRect(10,20,2,12),ui->line2);
    SetQPAnimation(1700,animationline3,QRect(15,20,2,12),ui->line3);
    SetQPAnimation(1800,animationline4,QRect(20,20,2,12),ui->line4);
}

btForm::~btForm()
{
    delete ui;
}

int btForm::getid()
{
    return id;
}

void btForm::seticon(QString btIcon, QString content, int mid)
{
    ui->bticon->setPixmap(QPixmap(btIcon));
    ui->bttext->setText(content);
    this->id=mid;
}

void btForm::mousePressEvent(QMouseEvent *event)
{
    (void)event;
    ui->btstyle->setStyleSheet(
            "#btstyle{"
            "    background-color: #aaff7f;"
            "    color: white;"
            "}");
    emit btsignal(this->getid());
}

void btForm::SetQPAnimation(int t,QPropertyAnimation* pat,QRect rect,QLabel* label )
{
    pat=new QPropertyAnimation(label,"geometry",this);
    pat->setDuration(t);
    pat->setKeyValueAt(0,rect);
    int gy;
    QRect newrect=rect;
    gy=label->geometry().y()-4;
    newrect.setY(gy);
    pat->setKeyValueAt(1,newrect);
    pat->setLoopCount(-1);
    pat->start();
}

void btForm::showanimal()
{
    ui->line1->show();
    ui->line2->show();
    ui->line3->show();
    ui->line4->show();
}

void btForm::hideanimal()
{
    ui->line1->hide();
    ui->line2->hide();
    ui->line3->hide();
    ui->line4->hide();

}

void btForm::clearbg()
{
    ui->btstyle->setStyleSheet("#btstyle:hover{ background:#D8D8D8;} ");
}

void btForm::showAnimal(bool isShow)
{
    if(isShow)
    {
        hideanimal();
    }else
    {
       showanimal();
    }
}


